package com.zhihuishu.treenity.controller.course;


import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhihuishu.micro.bbs.openapi.onlineschool.dto.OnlinePostModelOpenDto;
import com.zhihuishu.micro.bbs.openapi.remote.RemoteException;
import com.zhihuishu.remote.RemoteResult;
import com.zhihuishu.treenity.controller.BaseController;
import com.zhihuishu.treenity.log.LoggerCollectionEnum;
import com.zhihuishu.treenity.service.course.BBSCourseService;

/**
 * 
 * @author shehuaiyang
 * @date 2016年10月28日 上午9:55:41
 * @modifyNote
 * @version 1.0
 */
@Controller
@RequestMapping("/course/thirdStep/disscussion")
public class ThirdStepDisscussionController extends BaseController {
	
	
	@Resource
	private BBSCourseService bbsCourseService;
		
     /**
	 * 查询章讨论列表
	 * @Description
	 * @author shehuaiyang
	 * @date 2016年10月18日 下午3:33:15
	 * @modifyNote 
	 * @param courseId
	 * @param chapterId
	 * @return
	 */
    @Override
    protected LoggerCollectionEnum getCollectionEnum() {
        return LoggerCollectionEnum.disscussionCollection;
    }
	 /**
	 * 新增章模板
	 * @Description
	 * @author shehuaiyang
	 * @date 2016年10月19日 下午4:43:21
	 * @modifyNote 
	 * @param onlinePostModelOpenDto
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/create")
	public  RemoteResult<OnlinePostModelOpenDto> save(final OnlinePostModelOpenDto onlinePostModelOpenDto) {
		onlinePostModelOpenDto.setUserId(getLoginUID());
        RemoteResult<OnlinePostModelOpenDto> result = new ResultRequestAndParser<OnlinePostModelOpenDto>("建课业务", "zhihuishu-thirdStep-disscussion", "新增帖子", "save") {
            @Override
            public RemoteResult<OnlinePostModelOpenDto> request(Long curUserId) {
            	RemoteResult<OnlinePostModelOpenDto> rs = null;
				try {
					rs = bbsCourseService.saveModel(onlinePostModelOpenDto);
				} catch (RemoteException e) {
					log.error(e.getMessage());
				};
            	return rs;
            }
        }.get();
		return result;

	}
	/**
	 * 修改章模板
	 * @Description
	 * @author shehuaiyang
	 * @date 2016年10月19日 下午4:43:11
	 * @modifyNote 
	 * @param onlinePostModelOpenDto
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/update",method={RequestMethod.GET,RequestMethod.POST})
	public RemoteResult<OnlinePostModelOpenDto> update(final OnlinePostModelOpenDto onlinePostModelOpenDto) {
		onlinePostModelOpenDto.setUserId(getLoginUID());
        RemoteResult<OnlinePostModelOpenDto> result = new ResultRequestAndParser<OnlinePostModelOpenDto>("建课业务", "zhihuishu-thirdStep-disscussion", "修改帖子", "update") {
            @Override
            public RemoteResult<OnlinePostModelOpenDto> request(Long curUserId) {
            	RemoteResult<OnlinePostModelOpenDto> rs = null;
				try {
					rs = bbsCourseService.updateModel(onlinePostModelOpenDto);
				} catch (RemoteException e) {
					log.error(e.getMessage());
				};
            	return rs;
            }
        }.get();
		return result;
	}
	/**
	 * 删除章讨论
	 * @Description
	 * @author shehuaiyang
	 * @date 2016年10月28日 下午5:13:20
	 * @modifyNote 
	 * @param discussionId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delete")
	public RemoteResult<Void> delete(@RequestParam(value="discussionId",required=false) final Integer discussionId) {
    RemoteResult<Void> result = new ResultRequestAndParser<Void>("建课业务", "zhihuishu-thirdStep-disscussion", "删除帖子", "delete") {
        @Override
        public RemoteResult<Void> request(Long curUserId) {
        	RemoteResult<Void> rs = null;
			try {
				rs = bbsCourseService.deleteModelById(discussionId);
			} catch (RemoteException e) {
				log.error(e.getMessage());
			}
        	return rs;
        }
    }.get();
	return result;	
  }
}